from django.contrib.auth.models import User 
from socialgraph.models import ThoughtLink


def get_authors_user_follows(user):
    ul = ThoughtLink.objects.filter(from_author = user).values('to_author')
    return User.objects.filter(id__in=[i['to_author'] for i in ul])

def get_authors_follwing_user(user):
    ul = ThoughtLink.objects.filter(to_author = user).values('from_author')
    return User.objects.filter(id__in=[i['from_author'] for i in ul])

def get_mutual_followers(user):
    follows = ThoughtLink.objects.filter(from_author = user).values('to_author')
    following = ThoughtLink.objects.filter(to_author = user).values('from_author')
    follows_set   = set([i['to_author'] for i in follows])
    following_set = set([i['from_author'] for i in following])
    return User.objects.filter(id__in=(follows_set.intersection(following_set))      
